

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>数据操作 - 数据表格</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="/static/lib/layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="/static/lib/layuiadmin/style/admin.css" media="all">
</head>
<body>

  <div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
      <a lay-href="">主页</a>
      <a><cite>组件</cite></a>
      <a><cite>数据表格</cite></a>
      <a><cite>数据操作</cite></a>
    </div>
  </div>
  
  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">
      <div class="layui-col-md12">
        <div class="layui-card">
          <div class="layui-card-header">数据操作</div>
          <div class="layui-card-body">
            <div class="layui-btn-group test-table-operate-btn" style="margin-bottom: 10px;">
              <button class="layui-btn" data-type="getCheckData" onclick="getAllData()">获取选中行数据</button>
              <button class="layui-btn" data-type="getCheckLength">获取选中数目</button>
              <button class="layui-btn" data-type="isAll">验证是否全选</button>
            </div>

            <div id="sysUserGrid" title="" showHeader="true" class="mini-datagrid" style="width:100%;height:100%;" url="sysUser/pageList.do" idField="userId"
                 allowResize="true"
                 sizeList="[10,20,50,100]" pageSize="20" multiSelect="true" pageIndexField="page" pageSizeField="rows" dataField="rows"
                 onrowdblclick="onrowdblclick">
              <div property="columns" style="display: none;">
                <div type="indexcolumn" width="40" headerAlign="center">序号</div>
                <!---请手动修改各个列宽度，建议都设数字；让一个或两个设定按照百分比设置，百分比之和等于100%；操作列如果只有修改和删除时一般不用修改---->
                <div field='userName'   headerAlign='center' allowSort='true'>姓名</div>
                <div field='userSex'  headerAlign='center' allowSort='true' cellStyle="text-align:center;" renderer="formatSex">性别</div>
                <!--<div field='orgId' width='10%' headerAlign='center'  allowSort='true' renderer="formatOrgId">所属机构</div>-->
                <div field='policeRank'  headerAlign='center' allowSort='true'>职务</div>
                <div field='userBirthday'  headerAlign='center' dateFormat="yyyy-MM-dd" allowSort='true'>生日</div>
                <div field='userPhone'  headerAlign='center' allowSort='true'>手机号码</div>
                <div field='userEmail'  headerAlign='center' allowSort='true'>邮箱号</div>
                <div field="userCertificateType"  headerAlign="center" allowSort="false" cellStyle="text-align:center;" renderer="formatCerType">证件类型</div>
                <div field="userCertificateNum"  headerAlign="center" allowSort="false" cellStyle="text-align:center;">证件号</div>
                <div field="userId"  headerAlign="center" allowSort="false" cellStyle="text-align:center;" renderer="sysUseroperation">操作</div>
              </div>
            </div>
            
            <!--<table class="layui-hide" id="test-table-operate" lay-filter="test-table-operate"></table>-->
            
            <script type="text/html" id="test-table-operate-barDemo">
              <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
              <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
              <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
            </script>
          </div>
        </div>
      </div>
    </div>
  </div>
  
  <script src="/static/lib/layuiadmin/layui/layui.js"></script>
  <script src="../../../common/jquery-3.3.1.min.js"></script>
  <script>
      layui.config({
          base: '/static/lib/layuiadmin/' //静态资源所在路径
      })
  </script>
  <script src="../../../common/dataGrid.js"></script>
  <script>
    var grid= dataGrid.init("sysUserGrid");
    grid.load();
    /**
     * 格式化性别
     */
    Sex={
        "0": "男" ,
        "1":"女"
    };
    function formatSex(e){
        var value = e.value;
        if(value == "")
            return "";
        return Sex[value];
    }
    /**
     * 格式化证件类型
     */
    certificateType= {
        "0": "身份证" ,
        "1":"护照",
        "2":"军官证"
    };
    function formatCerType(e){
        var value = e.value;
        if(value == "")
            return "";
        return certificateType[value];
    }

    //对内部人员进行修改删除操作
    function  sysUseroperation(e){
        var row=e.record;
        //return"<a class='mini-button' hideFocus='' href='javascript:void(0)' onClick='editData(\""+e.value+"\")'><span class='mini-button-text  mini-button-icon icon-edit'>修改</span></a><span class='separator'></span>" +
        //	  "<a class='mini-button' hideFocus='' href='javascript:void(0)' onClick='removeData(\""+e.value+"\",\""+row.userName+"\")'><span class='mini-button-text  mini-button-icon icon-remove'>删除</span></a>";

       /* return "<button type=\"button\" class=\"btn btn-small btn-primary btn-edit\" onclick='getdata()'>修改</button>"+
            "<button type=\"button\" class=\"btn btn-small btn-primary btn-edit\">修改</button>";*/
       return " <a class=\"layui-btn layui-btn-primary layui-btn-xs\" lay-event=\"detail\" onclick='select()'>查看</a>\n" +
           "              <a class=\"layui-btn layui-btn-xs\" lay-event=\"edit\">编辑</a>\n" +
           "              <a class=\"layui-btn layui-btn-danger layui-btn-xs\" lay-event=\"del\">删除</a>";
    }

    function getAllData(){
        console.log(grid.getAllData())
    }

    function getdata(){
        //
        grid.reload({});
    }

    function onrowdblclick(data){
        console.log(data)
    }

    function select(){
        alert(111)
    }
  </script>

 <!-- <script>
  layui.config({
    base: '/static/lib/layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'table'], function(){
    var table = layui.table
    ,admin = layui.admin;
  
    table.render({
      elem: '#test-table-operate'
      ,url: layui.setter.base + 'json/table/user.js'
      ,width: admin.screen() > 1 ? 892 : ''
      ,height: 332
      ,cols: [[
        {type:'checkbox', fixed: 'left'}
        ,{field:'id', width:80, title: 'ID', sort: true, fixed: 'left'}
        ,{field:'username', width:80, title: '用户名'}
        ,{field:'sex', width:80, title: '性别', sort: true}
        ,{field:'city', width:80, title: '城市'}
        ,{field:'sign', width: 160, title: '签名'}
        ,{field:'experience', width:80, title: '积分', sort: true}
        ,{field:'wealth', width:135, title: '财富', sort: true}
        ,{field:'classify', width:80, title: '职业'}
        ,{field:'score', width:80, title: '评分', sort: true, fixed: 'right'}
        ,{width:178, align:'center', fixed: 'right', toolbar: '#test-table-operate-barDemo'}
      ]]
      ,page: true
    });
    
    //监听表格复选框选择
    table.on('checkbox(test-table-operate)', function(obj){
      console.log(obj)
    });
    //监听工具条
    table.on('tool(test-table-operate)', function(obj){
      var data = obj.data;
      if(obj.event === 'detail'){
        layer.msg('ID：'+ data.id + ' 的查看操作');
      } else if(obj.event === 'del'){
        layer.confirm('真的删除行么', function(index){
          obj.del();
          layer.close(index);
        });
      } else if(obj.event === 'edit'){
        layer.alert('编辑行：<br>'+ JSON.stringify(data))
      }
    });
    
    var $ = layui.$, active = {
      getCheckData: function(){ //获取选中数据
        var checkStatus = table.checkStatus('test-table-operate')
        ,data = checkStatus.data;
        layer.alert(JSON.stringify(data));
      }
      ,getCheckLength: function(){ //获取选中数目
        var checkStatus = table.checkStatus('test-table-operate')
        ,data = checkStatus.data;
        layer.msg('选中了：'+ data.length + ' 个');
      }
      ,isAll: function(){ //验证是否全选
        var checkStatus = table.checkStatus('test-table-operate');
        layer.msg(checkStatus.isAll ? '全选': '未全选')
      }
    };
    
    $('.test-table-operate-btn .layui-btn').on('click', function(){
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
  
  });
  </script>-->
</body>
</html>